package com.dyh.quickdemozwei.groovy;

import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyShell;

/**
 * @Author: yhdong
 * @Date: 2021/9/9 20:22
 */
public class HelloG {
//    public static void main(String[] args) {
//        Binding binding = new Binding();
//        String src = "retrun new groovy.json.JsonSlurper().parseText('{\"name\":\"Hello\"}').name";
//        GroovyShell groovyShell = new GroovyShell(binding);
//        Object data = groovyShell.evaluate(src);
//        System.out.println();
//    }

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        String src = "retrun new groovy.json.JsonSlurper().parseText('{\"name\":\"Hello\"}').name";

        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        Class<?> clazz = groovyClassLoader.parseClass(src);
        GroovyObject groovyObject  =  (GroovyObject)clazz.newInstance();
        Object res = groovyObject.invokeMethod(src,null);

        System.out.println();
    }
}
